
import { getParams, showDetailPage } from '@/utils';
import { isAffairValid } from '../collaborationFunc/collaboration';
import collaboration from '@/utils/collaboration';
import smartCodeMixin from '@/mixins/smart-code-mixin';


export default {
  mixins: [smartCodeMixin],
  data() {
    return {
      tableSlotNames: ['subject'],
      isSecretLevelEnable: false, // 需要后端数据  ${ctp:isSecretLevelEnable()};
      hasDoc: false, // 需要后端数据  "${ctp:hasPlugin('doc')}";
      haveNewColl: false, // 需要后端数据
      newColNodePolicy: {
        "relateAttachment": false,
        "editWorkFlow": true,
        "repeatSend": true,
        "cancel": true,
        "reMove": false,
        "uploadAttachment": true,
        "uploadRelDoc": true,
        "print": true,
        "pigeonhole": true,
        "forward": true
      }, // 需要后端数据  {"newColNodePolicy":'${newColnewColNodePolicy}'};
      resources: null, // 需要后端数据
      emailShow: true, // 需要后端数据  ${v3x:hasPlugin('webmail')};
      isV5Member: true, // 需要后端数据  ${CurrentUser.externalType == 0};
      isFormAdvanced: true, // 需要后端数据  "${ctp:hasPlugin('formAdvanced')}";
      hasDumpData: true, // 需要后端数据  "${ctp:escapeJavascript(hasDumpData)}";
      showHandoverButton: true, // 需要后端数据  "${ctp:escapeJavascript(showHandoverButton)}";
      addinMenus: true, // 需要后端数据 var addinMenus = new Array();
      listFrom: 'listSent', // 需要后端数据,
      canDel: false,
      _getCtpTop: null,
      dataType: '', // 0：当前数据；1：转储数据
      deduplication: false,
      aiProcessing: false,
      selectedRows: [],
      allToolBtns: [],
      searchConditionsValue: {}
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.getCtpTop();
      this.getResources();
      this.urlParamObj = getParams(window.location.search);
    },
    getCtpTop() {
      this._getCtpTop = window.getCtpTop();
    },
    getResources() {
      this.resources = window._resources;
    },
    metaDataChangeHandle(data) {
      const { globalParam } = data;
      this.initGlobalParam(globalParam);
    },
    initGlobalParam(globalParam) {
      if (globalParam) {
        const keyList = ["newColNodePolicy", "hasDumpData", "showHandoverButton", "canDel", "haveNewColl"];
        keyList.forEach(key => {
          this[key] = globalParam[key];
        });
        this.supportSmartCode = globalParam.supportSmartCode;
      }
      this.hasDoc = window._hasPlugin('doc');
      this.isFormAdvanced = window._hasPlugin('formAdvanced');
      this.emailShow = window._hasPlugin('webmail');
      if (this.isHaveSmartCodePermission()) {
        this.allToolBtns.push(this.smartCodeBtnInfo);
      }
    },
    onRowClick(row) {
      const self = this;
      const { dataType } = this;
      const { affairId } = row;
      if (!isAffairValid(affairId)) {
        callBackendMethod("handoverManager", "removeAffairById", affairId, {
          success: function () {
            self.resetTableData();
          }
        });
        return;
      }
      var url = _ctxPath + "/collaboration/collaboration.do?method=summary&openFrom=listSent&affairId=" + affairId + "&dumpData=" + dataType;
      showDetailPage(url, affairId);
    },
    // 智码扫码成功后，智码预处理时，获取解码参数
    getSmartCodeDecodeParam(data) {
      const obj = this.searchConditionsValue;
      obj.openFrom = 'listSent';
      return obj;
    },
    // 智码扫码成功后回调
    smartCodeCallBack(data) {
      collaboration.smartCodeCallBack(data);
    },
    handleToolClick(buttonId, { selectedRows, searchConditionsValue }, resetTableData) {
      this.searchConditionsValue = searchConditionsValue;
      this.showSmartCode && this.showSmartCode();
      document?.activeELement?.blur();
    }
  }
};
